package EA.testproblems;
import EA.*;

/**
<table border="0" cellpadding="2" cellspacing="0">
<tr bgcolor="#a0a0a0">
  <td colspan="2" valign="top"><b>Problem description</b></td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top" width="200"><b>Name:</b></td>
  <td valign="top">Ursem multimodal 7</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Nickname:</b></td>
  <td valign="top">&nbsp;</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Intended usage:</b></td>
  <td valign="top">Test of a multimodal algoritms is capable of spotting 
very shallow peaks much smaller than global maxima and far from it.
</td>
</tr>

<tr>
  <td colspan="2" valign="top">&nbsp;</td>
</tr>
<tr bgcolor="#a0a0a0">
  <td colspan="2" valign="top"><b>Problem details</b></td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Function:</b></td>
  <td valign="top">sin(x*cos(y*0.5)+0.1*(0.4*x+y))*(10-abs(x))*(10-abs(y))-0.5*(x*x+y*y)
</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Plots:</b></td>
  <td valign="top"><img src="../../images/testproblems/ursemmultimodal7.gif">&nbsp;&nbsp;
<img src="../../images/testproblems/ursemmultimodal7_contour.gif"></td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Ranges:</b></td>
  <td valign="top">x = [-10:10]&nbsp;&nbsp;y = [-10:10] </td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Type:</b></td>
  <td valign="top">Maximization</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>No. of maximas:</b></td>
  <td valign="top">10</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>No. of minimas:</b></td>
  <td valign="top">8</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Optimum radius:</b></td>
  <td valign="top">0.2
</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Optimum descriptions:</b></td>
  <td valign="top">The global maxima and most of the local maximas are 
  located at one end of the search space. Some of these maximas are
  hard to detect.
</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Known optimums:</b></td>
  <td valign="top">
  GMAX(1.388641622,0),
  LMAX(-1.706402073, 4.252587433), 
  LMAX(-6.807596109, 5.876462701), 
  LMAX(-2.725868813, -4.598834689), 
  LMAX(-9.090925925, -.4061490444e-1), 
  LMAX(4.386345721, -5.385076083), 
  LMAX(-7.631546029, -5.862860196), 
  LMAX(5.352159430, 5.506612881),
  LMAX(-4.3015332836,0),
  LMAX(7.039222042,0),
  LMIN(1.502887502, -4.662002695), 
  LMIN(2.673102072, 4.929749385),
  LMIN(-1.418278549,0),
  LMIN(4.439305856,0),
  LMIN(10,-10),
  LMIN(10,10),
  LMIN(-10,-10),
  LMIN(-10,10)
<br><font size=1>Capital letters 
means that the precise optimum is known, lowercase letters is the best known 
so far.</font></td>
</tr>
<tr>
  <td colspan="2" valign="top">&nbsp;</td>
</tr>
<tr bgcolor="#a0a0a0">
  <td colspan="2" valign="top"><b>Plotting details</b></td>
</tr>

<tr bgcolor="#e0e0e0">
  <td valign="top"><b>GNUPlot code:</b></td>
  <td valign="top">
  set hidden3d<br>
  set isosamples 50<br>
  set view 70,15<br>
splot [-10:10] [-10:10] sin(x*cos(y*0.5)+0.1*(0.4*x+y))*(10-abs(x))*(10-abs(y))-0.5*(x*x+y*y)
</td>
</tr>
</table>
*/
public class UrsemMultimodal7 extends NumericalProblem
{

  // Easier way to build max
  private double[][] lmax =  {{-1.706402073, 4.252587433}, 
			      {-6.807596109, 5.876462701}, 
			      {-2.725868813, -4.598834689}, 
			      {-9.090925925, -.4061490444e-1}, 
			      {4.386345721, -5.385076083}, 
			      {-7.631546029, -5.862860196}, 
			      {5.352159430, 5.506612881},
			      {1.388641622,0},
			      {-4.3015332836,0},
			      {7.039222042,0}};
  private double[][] lmin =  {{1.502887502, -4.662002695}, 
			      {2.673102072, 4.929749385},
			      {-1.418278549,0},
			      {4.439305856,0},
			      {10,-10},
			      {10,10},
			      {-10,-10},
			      {-10,10}};

  public UrsemMultimodal7()
    {
      super();

      double[] optimums;

      name = "Ursem Multimodal 7";
      objectivefunction = new NumericalFitness(){
	      public double Fitness_calcFitness_inner(double[] realpos)
	      {
		  return Math.sin(realpos[0]*Math.cos(realpos[1]*0.5)+0.1*(0.4*realpos[0]+realpos[1]))*(10-Math.abs(realpos[0]))*(10-Math.abs(realpos[1]))-0.5*(realpos[0]*realpos[0]+realpos[1]*realpos[1]);

	      };
	  };

      dimensions = 2;
      ismaximization = true;
      optimumradius = 0.2;

      intervals = new Interval[2];
      intervals[0] = new Interval(-10,10);
      intervals[1] = new Interval(-10,10);

      // Set up known maximas
      knownmaxima = new NumericalOptimum[lmax.length];

      for (int i=0;i<lmax.length;i++) {
	optimums = new double[dimensions];
	optimums[0] = lmax[i][0];
	optimums[1] = lmax[i][1];
	knownmaxima[i] = new NumericalOptimum(optimums, objectivefunction.calcFitness(optimums), true, false, i);
      }

      // Set up known minimas
      knownminima = new NumericalOptimum[lmin.length];

      for (int i=0;i<lmin.length;i++) {
	optimums = new double[dimensions];
	optimums[0] = lmin[i][0];
	optimums[1] = lmin[i][1];
	knownminima[i] = new NumericalOptimum(optimums, objectivefunction.calcFitness(optimums), false, false, i);
      }
    }
}
